<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-tickets"></i> 批次管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <!--<div class="handle-box">-->
                <!--<el-input v-model="select_word" placeholder="筛选关键词" class="handle-input mr10"></el-input>-->
                <!--<el-button type="primary" icon="search" @click="search">搜索</el-button>-->
            <!--</div>-->
            <el-table :data="tableData" v-loading="loadingFlag" border  ref="multipleTable">
                <!--<el-table-column type="index" width="40"></el-table-column>-->
                <!-- sortable -->
                <!-- <el-table-column label="是否已删除" width="100">
                      <template slot-scope="scope" >
                          <div style="text-align:center">{{scope.row.state == 1 ? '是':'否'}}</div>
                      </template>
                </el-table-column> -->
                <el-table-column prop="batch_id" label="批号编号"   width="150"></el-table-column>
                <el-table-column prop="batch_type" label="课程类型" width="120"></el-table-column>
                <el-table-column label="开课时间" width="120">
                     <template slot-scope="scope">
                        {{scope.row.start_time - 0 | formatTime}}
                    </template>
                </el-table-column>
                <el-table-column prop="apply_sum" label="报名人数" width="150"></el-table-column>
                <el-table-column prop="pending_job" label="待处理作业">
                </el-table-column>
                <el-table-column prop="state" label="状态" width="100">
                    <template slot-scope="scope">
                        {{scope.row.state == 1 ? '已删除': ''}}
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="200">
                    <template slot-scope="scope" >
                        <el-button size="small" type="primary" plain @click="$router.push({path: '/jobManage',query: {'batch_id': scope.row.batch_id}})">作业管理</el-button>
                        <el-button size="small" type="primary" @click="$router.push({path: '/studentBatch',query: {'batch_id': scope.row.batch_id}})">查看编辑</el-button>
                        <!-- <el-button size="small" type="danger" @click="delCourseBatchShow(scope.row,scope.$index)">删除</el-button> -->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination @current-change="handleCurrentChange" layout="prev, pager, next, jumper" :total="total" :page-size="10">
                </el-pagination>
            </div>
        </div>
        <!-- 删除批次管理 提示框 -->
        <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <div class="del-dialog-cnt">
                <el-input v-model="pass_word" placeholder="请输入管理员密码" type="password"></el-input>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="submitdelCourseBatch()">确 定</el-button>
            </span>
        </el-dialog>

    </div>
</template>

<script>
    import {
        obtainStudentBatchList,
        delCourseBatch
    } from "@/config/api";
    import {dateRegExp} from '@/config/filter';
    export default {
        name: 'basetable',
        data() {
            return {
                loadingFlag: false,
                url: './static/vuetable.json',
                tableData: [],
                cur_page: 1,
                multipleSelection: [],
                select_cate: '',
                select_word: '',
                del_list: [],
                is_search: false,
                editVisible: false,
                delVisible: false,
                form: {
                    name: '',
                    date: '',
                    address: ''
                },
                idx: -1,

                // 总条数
                total: 0,
                // 管理员密码
                pass_word: '',
            }
        },
        filters: {
            formatTime (time) {
                return dateRegExp(( time - 0 ),'yyyy-MM-dd')
            }
        },
        computed: {
        },
        created() {
          
        },
        mounted () {
            this.getData();
        },
        methods: {
            // 获取 easy-mock 的模拟数据
            async getData() {
                this.loadingFlag = true;
                let data = await obtainStudentBatchList(this.cur_page);
                console.log("数据", data);
                this.tableData = data.list;
                this.total = data.total;
                this.loadingFlag = false;
            },
            // 分页导航
            handleCurrentChange(val) {
                this.cur_page = val;
                this.getData();
            },
            // 删除批次管理 对话框 显示
            delCourseBatchShow(row, index) {
                this.delVisible = true;
                // 保存被点击的数据
                this.saveData = row;
                console.log("删除批次管理 对话框 显示", row, index);
            },
             // 删除批次管理
            async submitdelCourseBatch() {
                // 对话框删除
                this.delVisible = false;
                await delCourseBatch(this.saveData.batch_id, this.pass_word,localStorage.getItem('ms_username'))
                    .then(res => {
                        console.log("删除批次", res);
                        if (res.msg === "success") {
                            this.$message({
                                message: "删除成功",
                                type: "success"
                            });
                            // 重新获取数据
                            this.getData();
                        } else {
                            this.$message.error(res.msg);
                        }

                        this.pass_word = "";
                    })
                    .catch(err => {
                        console.log("错误信息：", err);
                    });
            },
        }
    }

</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }
</style>
